home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / OnRamp / bin / htnetwork.z / htnetwork
Encoding:
Text File  |  1997-07-30  |  1.6 KB  |  58 lines

  1. #! /usr/bin/perl5
  2. #
  3. # htnetwork
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: htnetwork,v 1.5 1997/04/17 23:38:16 shotes Exp $
  21.  
  22. #
  23. # Simple script to parse the output of netstat and ifconfig and provide
  24. # a table of the results.
  25. #
  26.  
  27. open(NS, "/usr/etc/netstat -in|");
  28. $index = 0;
  29. while (<NS>) {
  30.     if ($index == 0) {        # skip row of headers
  31.         $index++;
  32.         next;
  33.     }
  34.  
  35.     next if ($_ =~ /^\s/);        # skip alias rows
  36.  
  37.     # These are fixed length fields.
  38.     $one = substr($_, 0, 5);
  39.     $up = ($one =~ /\*\s*$/) ? 0 : 1;
  40.     $one =~ /\*|\s/;
  41.     $ifname = $`;
  42.  
  43.     next if ($ifname =~ /^lo/);    # skip loopback
  44.  
  45.     $data = join(' ',`/usr/etc/ifconfig $ifname`);
  46.     $ip = ($data =~ /inet (\d+\.\d+\.\d+\.\d+)/) ? $1 : "";
  47.     $netmask = ($data =~ /netmask (\S+)/) ? $1 : "";
  48.  
  49.     ($hostname,$dm1,$dm2,$dm3,@dm4) = 
  50.         (gethostbyaddr(pack('C4', split(/\./, $ip)),2));
  51.  
  52.     printf("%d:%s:%d:%s:%s:%s\n", $index, $ifname, $up, $ip, $netmask,
  53.         $hostname);
  54.  
  55.     $index++;
  56. }
  57. close(NS);
  58.